<? if(isset($_SESSION['admin']['user_type']) && $_SESSION['admin']['user_type']=="admin"){?>
<script>
	window.location='/admin/admin_allusers-list';
</script>
<?} else if(isset($_SESSION['admin']['user_type']) && $_SESSION['admin']['user_type']=="superadmin"){?>
<script>
	window.location='/admin/allusers-list';
</script>
<?}else{?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>CBAY</title>
		<link href="<?php echo $this->basePath() ?>/css/style.css" type="text/css" rel="stylesheet" />
	</head>
	<body>
		<div class="bg_top"><img src="<?php echo $this->basePath() ?>/images/bg_top.png" /></div>
		<div id="wrapper">
			<section class="login">
				<h1>Admin Login</h1>
						<div class="login_sub">
								<div class="login_input">
									<input type="text" id="adminUsername" name="adminUsername" placeholder="User Email"/>
								</div>
								<span id="erroradminUsername"  style="color:red;margin-left:18%;" ></span>
								<div class="login_psw">
									<input type="password" id="adminPassword"  name="adminPassword"/>
								</div>
								<span id="erroradminPassword" style="margin-left:18%;color:red;"></span>
								<div class="sign_in">
									<button onclick="return validateadminLogin();">Sign In</button>
									<h4><a href="/users/forgetpassword">Forgot Password?</a></h4>
								</div>					
						</div>
					<span id="loginFailed" style="margin-left:5%;color:red;"></span>
			</section>			
		</div>
		<div class="bg_bottom"><img src="<?php echo $this->basePath() ?>/images/bg_bottom.png" /></div>
	</body>
</html>
<script>
	function validateadminLogin(){
		var flag=true;	
		if($('#adminUsername').val()==""){		
			$('#erroradminUsername').html('*User Name Required');
			flag=false;
		}else{
			$('#erroradminUsername').html('');
		}
		if($('#adminPassword').val()==""){
			$('#erroradminPassword').html('*Password Required');
			flag=false;
		}else{
			$('#erroradminPassword').html('');
		}
		if(flag==false){ 
			return false;
		}else{ 
			var userEmail=$('#adminUsername').val();
			var userPassword=$('#adminPassword').val();
			$.ajax({
				type:'POST',
				datatype:'json',
				url:   '/admin/index',
				data:{adminUsername:userEmail,adminPassword:userPassword},
				success: function(data){
					if(data.output=='notsuccess'){
						$('#loginFailed').html('*Please Enter Valid Username And Password!');
					}else if(data.output=='success' && data.type=='superadmin'){	
						$('#loginFailed').html('');
						window.location='/admin/allusers-list';
					}else if(data.output=='success' && data.type=='admin'){	
						$('#loginFailed').html('');
						window.location='/admin/admin_allusers-list';
					}
				}
			});
		}	
	}
</script>
<?}?>
